#include "selectgamedialog.h"

const int SelectGameDialog::ID_PLAYER_VS_AI_BUTTON=180;
const int SelectGameDialog::ID_AI_VS_AI_BUTTON=181;
const int SelectGameDialog::ID_TBTN_GREEDY_FRONT=182;
const int SelectGameDialog::ID_TBTN_GREEDY_BACK=183;
const int SelectGameDialog::ID_TBTN_GREEDY_FRONT1=184;
const int SelectGameDialog::ID_TBTN_GREEDY_BACK1=185;
const int SelectGameDialog::ID_TBTN_GREEDY_FRONT2=186;
const int SelectGameDialog::ID_TBTN_GREEDY_BACK2=187;
const int SelectGameDialog::ID_TBTN_SLOW=188;
const int SelectGameDialog::ID_TBTN_MEDIUM=189;
const int SelectGameDialog::ID_TBTN_FAST=190;

SelectGameDialog::SelectGameDialog(wxWindow *parent,const wxString&title,int typedialog) : wxDialog((wxWindow*)parent,wxID_ANY,title,wxDefaultPosition,wxSize(400,520))
{
    this->EnableCloseButton(false);
    this->typedialog=typedialog;
    if (typedialog==ID_PLAYER_VS_AI_BUTTON)
      this->SetLabel(wxT("Game Setting Player vs AI"));
    else if  (typedialog==ID_AI_VS_AI_BUTTON)
      this->SetLabel(wxT("Game Setting AI vs AI"));

    parentpanel = new wxPanel(this,wxID_ANY);

    wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);

    wxStaticBox *st = new wxStaticBox(parentpanel, -1, wxT("Board"),wxPoint(5, 5), wxSize(350, 70));

    rbboard1 = new wxRadioButton(parentpanel,wxID_ANY,wxT("8x8"),wxPoint(15,30),wxDefaultSize,wxRB_GROUP);
    rbboard2 = new wxRadioButton(parentpanel,wxID_ANY,wxT("10x10"),wxPoint(15,55),wxDefaultSize);

    if (typedialog==ID_PLAYER_VS_AI_BUTTON)
    {
        wxStaticText *namequestion = new wxStaticText(parentpanel,wxID_ANY,wxT("Input your name :  "),wxPoint(15,100));
        nametext = new wxTextCtrl(parentpanel,wxID_ANY,wxT("player1"),wxPoint(150,100));

        wxStaticBox *st = new wxStaticBox(parentpanel, -1, wxT("AI-enemy algorithm"),wxPoint(5, 130), wxSize(350, 70));
//        wxRadioButton *rbgreedyfront = new wxRadioButton(childpanel,10,wxT("greedy by front"),wxPoint(15,60),wxDefaultSize,wxRB_USE_CHECKBOX);
//        wxRadioButton *rbgreedyback = new wxRadioButton(childpanel,11,wxT("greedy by back-up"),wxPoint(15,85),wxDefaultSize);

        tbtngreedyfront = new wxToggleButton(parentpanel, wxID_ANY, wxT("greedy by front"), wxPoint(15, 150));
//        tbtngreedyfront->SetValue(true);
        Connect(ID_TBTN_GREEDY_FRONT,wxEVT_COMMAND_TOGGLEBUTTON_CLICKED,wxCommandEventHandler(SelectGameDialog::OnToggleButtonGreedyFront));
        tbtngreedyback = new wxToggleButton(parentpanel,wxID_ANY,wxT("greedy by back-up"),wxPoint(150,150));
        Connect(ID_TBTN_GREEDY_BACK,wxEVT_COMMAND_TOGGLEBUTTON_CLICKED,wxCommandEventHandler(SelectGameDialog::OnToggleButtonGreedyBack));
//        tbtngreedyback->SetValue(false);

//        wxStaticText *namequestion = new wxStaticText(parentpanel,wxID_ANY,wxT("Input your name :  "),wxPoint(15,100));
//        nametext = new wxTextCtrl(parentpanel,wxID_ANY,wxT("player1"),wxPoint(150,100));
//
//        wxStaticBox *st = new wxStaticBox(parentpanel, -1, wxT("AI-enemy algorithm"),wxPoint(5, 130), wxSize(350, 70));
//        wxRadioButton *rbgreedyfront = new wxRadioButton(parentpanel,wxID_ANY,wxT("greedy by front"),wxPoint(15,150),wxDefaultSize,wxRB_GROUP);
//        wxRadioButton *rbgreedyback = new wxRadioButton(parentpanel,wxID_ANY,wxT("greedy by back-up"),wxPoint(15,175),wxDefaultSize);
//        wxPuts(wxT("tercipta rbgreedy\n"));
    }
    else if (typedialog==ID_AI_VS_AI_BUTTON)
    {
        wxStaticBox *st = new wxStaticBox(parentpanel, -1, wxT("Game Speed"),wxPoint(5, 80), wxSize(350, 150));
        tbtnslow = new wxToggleButton(parentpanel, wxID_ANY, wxT("Slow"), wxPoint(15, 100));
        tbtnslow->SetValue(false);
        tbtnmedium = new wxToggleButton(parentpanel,wxID_ANY,wxT("Medium"),wxPoint(15,130));
        tbtnmedium->SetValue(false);
        tbtnfast = new wxToggleButton(parentpanel,wxID_ANY,wxT("Fast"),wxPoint(15,160));
        tbtnfast->SetValue(false);


        wxStaticBox *st1 = new wxStaticBox(parentpanel, -1, wxT("Black AI-enemy algorithm"),wxPoint(5, 240), wxSize(350, 100));
        tbtngreedyfront1 = new wxToggleButton(parentpanel,wxID_ANY,wxT("greedy by front"),wxPoint(15,260));
        tbtngreedyfront1->SetValue(false);
        tbtngreedyback1 = new wxToggleButton(parentpanel,wxID_ANY,wxT("greedy by back"),wxPoint(15,290));
        tbtngreedyback1->SetValue(false);
//        rbgreedyfront1 = new wxRadioButton(parentpanel,wxID_ANY,wxT("greedy by front"),wxPoint(15,225),wxDefaultSize,wxRB_GROUP);
//        rbgreedyback1 = new wxRadioButton(parentpanel,wxID_ANY,wxT("greedy by back-up"),wxPoint(15,245),wxDefaultSize);

        wxStaticBox *st2 = new wxStaticBox(parentpanel, -1, wxT("White AI-enemy algorithm"),wxPoint(5, 350), wxSize(350,   100));
        tbtngreedyfront2 = new wxToggleButton(parentpanel,wxID_ANY,wxT("greedy by front"),wxPoint(15,380));
        tbtngreedyfront2->SetValue(false);
        tbtngreedyback2 = new wxToggleButton(parentpanel,wxID_ANY,wxT("greedy by back"),wxPoint(15,410));
        tbtngreedyback2->SetValue(false);
//        wxRadioButton *rbgreedyfront2 = new wxRadioButton(parentpanel,wxID_ANY,wxT("greedy by front"),wxPoint(15,290),wxDefaultSize,wxRB_GROUP);
//        wxRadioButton *rbgreedyback2 = new wxRadioButton(parentpanel,wxID_ANY,wxT("greedy by back-up"),wxPoint(15,315),wxDefaultSize);
    }

    okselectbutton = new wxButton(this,wxID_ANY,wxT("FINISH SETTING"),wxDefaultPosition,wxSize(70,30));
    Connect(wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(SelectGameDialog::OnQuitSelect));

    vbox->Add(parentpanel,1);

    vbox->Add(okselectbutton,0,wxEXPAND|wxALL,5);


    SetSizer(vbox);
    Centre();
    ShowModal();
}

void SelectGameDialog::OnToggleButtonGreedyFront(wxCommandEvent& WXUNUSED(event))
{
    wxPuts(wxT("front!!\n"));
    tbtngreedyback->SetValue(false);
}

void SelectGameDialog::OnToggleButtonGreedyBack(wxCommandEvent& WXUNUSED(event))
{
    wxPuts(wxT("back!!\n"));
    tbtngreedyfront->SetValue(false);
}

void SelectGameDialog::OnQuitSelect(wxCommandEvent&event)
{
//    if (this->rbgreedyfront->GetValue())
//    {
//        wxPuts(wxT("rbgreedy front\n"));
//    }
//    else if (this->rbgreedyback->GetValue())
//    {
//        wxPuts(wxT("rbgreedy back\n"));
//    }

    if (typedialog==ID_PLAYER_VS_AI_BUTTON)
    {
        if (tbtngreedyfront->GetValue())
        {
            wxPuts(wxT("rbgreedy front\n"));
        }
        else
        {
            wxPuts(wxT("rbgreedy back\n"));
        }
    }

    if (typedialog==ID_AI_VS_AI_BUTTON)
    {
        if (tbtnslow->GetValue())
        {
            wxPuts(wxT("slow\n"));
        }
        if (tbtnmedium->GetValue())
        {
            wxPuts(wxT("medium\n"));
        }
        if (tbtnfast->GetValue())
        {
              wxPuts(wxT("fast\n"));
        }
        if (tbtngreedyfront1->GetValue())
        {
            wxPuts(wxT("front1"));
        }
        if (tbtngreedyback1->GetValue())
        {
            wxPuts(wxT("back1"));
        }
        if (tbtngreedyfront2->GetValue())
        {
            wxPuts(wxT("front2"));
        }
        if (tbtngreedyback2->GetValue())
        {
            wxPuts(wxT("back2"));
        }
    }
//    if (tbtnmedium->GetValue())
//    {
//        wxPuts(wxT("medium\n"));
//    }
//    if (tbtnfast->GetValue())
//    {
//        wxPuts(wxT("fast\n"));
//    }

    if (this->rbboard1->GetValue())
    {
        wxPuts(wxT("8x8 lhoo\n"));
    }
    else if (this->rbboard2->GetValue())
    {
        wxPuts(wxT("10x10 lhooo\n"));
    }
    event.Skip();
    this->Close(true);
}


